package com.nice.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.nice.Commons;
import com.nice.price.AgtdPrice;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
//@RequestMapping("/post")
public class LoginController {



    @GetMapping("/login")
    public ModelAndView login() {
        return new ModelAndView("login.html");
    }


    /**
     * 跳转价格列表页面
     * @return
     */
    @RequestMapping("/loginHtml")
    public ModelAndView priceSettingHtml(String name) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("login.html");
        return modelAndView;
    }

    /**
     * 登陆接口-设置会话
     * @param email
     * @param session
     * @return
     */
    @PostMapping("/toLogin")
    @ResponseBody
    public String toLogin(String email, HttpSession session){
        System.out.println("请求toLogin");
        if (session.getAttribute(Commons.LOGIN_NAME) == null) {
            session.setAttribute(Commons.LOGIN_NAME, email);
            return Commons.LOGIN_NAME;
        }else{
            String getAttribute = String.valueOf(session.getAttribute(Commons.LOGIN_NAME));
           return  getAttribute;
        }

    }


    @GetMapping("/hello")
    @ResponseBody
    public String hello2(){
        return "hello";
    }
}
